<?php
require_once('../inc/xml2.php');
switch($action){
	/************************************** list BEGIN ************************************************/
	case "list":
	$dwidth=array(0,50,50,60,120,120,250,200);

echo <<<EOT
	<div id="smalltab_container"></div>
	<div class="smalltab_line"></div>
	<div class="div_clear" style="height:10px;"></div>
	<div id="t1">
		<form id="pluginsform" onsubmit="return false;">
		<div class="tips_1"><b>提示</b><br />
	* 更多插件可以访问6KBBS官方论坛 <a href="http://www.6kbbs.com" target="_blank">http://www.6kbbs.com</a> </div>
		<div class="div_clear" style="height:10px;"></div>
		<table class="table_1" width="100%">
			<tr style="font-weight:bold;color:#333333;"><td class="td_6"><div class="rowdiv_0" style="width:{$dwidth[1]}px;">启用</div><div class="rowdiv_0" style="width:{$dwidth[3]}px;">顺序</div><div class="rowdiv_0" style="width:{$dwidth[4]}px;">插件预览</div><div class="rowdiv_0" style="width:{$dwidth[5]}px;">插件文件夹</div><div class="rowdiv_0" style="width:{$dwidth[6]}px;">插件名称/链接</div><div class="rowdiv_0" style="width:{$dwidth[6]}px;">插件注入代码</div><div class="rowdiv_0" style="width:{$dwidth[7]}px;">作者</div></td></tr>
		
EOT;
		$narray = array();
		$dir = '../plugins';
		$pluginsdir = dir($dir);
		$xml = new xmlParser();   
  		$defaultstyle="";
		$tmporder=array();
		while($entry = $pluginsdir->read()) {
			$tpldir = realpath($dir.'/'.$entry);
			if(!in_array($entry, array('.', '..')) && is_dir($tpldir)) {
				if(!empty($cache_plugins[$entry])){
					$tmporder[$entry]=$cache_plugins[$entry]['order'];
				}else{
					$tmporder[$entry]='N';
				}
			}
		}
		asort($tmporder);

		foreach($tmporder as $entry=>$order) {
			$tpldir = realpath($dir.'/'.$entry);
			if(!in_array($entry, array('.', '..')) && is_dir($tpldir)) {
				$config=array();
				$xmlstr=@file_get_contents("{$dir}/{$entry}/config.xml");
				if($xmlstr){
					$config= $xml->xml2array($xmlstr);
				}
				$checkbox="<input type='checkbox' name='tkeys[]' value='{$entry}' class='checkbox_css' />";
				$tempname="";
				if(!empty($cache_plugins[$entry])){
					$defaultstyle=$cache_plugins[$entry]['default'];
					$checkbox="<input type='checkbox' name='tkeys[]' value='{$entry}' checked='true' class='checkbox_css' />";
					$tempname=$cache_plugins[$entry]['name'];
					$templink=$cache_plugins[$entry]['link'];
					$tempcode=$cache_plugins[$entry]['code'];
				}else{
					$tempname=$config['name'];
					$templink=$config['link'];
					$tempcode=$config['code'];
				}
				$orderv = $cache_plugins[$entry]['order'];
				echo("<tr><td class=\"row_0\" style=\"line-height:150%;\">".
				"<div class='rowdiv_0' style='width:{$dwidth[1]}px;'>{$checkbox}</div>".
				"<div class='rowdiv_0' style='width:{$dwidth[3]}px;'><input type='text' size='4' name='torder[{$entry}]' value='{$orderv}' class=\"text_css\" /></div>".
				"<div class='rowdiv_0' style='width:{$dwidth[4]}px;'><img src='{$dir}/{$entry}/{$config['preview']}' border='0' />&nbsp;</div>".
				"<div class='rowdiv_0' style='width:{$dwidth[5]}px;'>{$entry}</div>".
				"<div class='rowdiv_0' style='width:{$dwidth[6]}px;'><input type='text' size='30' value='{$tempname}' name='tname[{$entry}]' class=\"text_css\" style=\"width:200px;\" /><div style='height:5px;'></div><textarea name='tlink[{$entry}]' style='width:200px; height:70px;'>{$templink}</textarea></div>".
				"<div class='rowdiv_0' style='width:{$dwidth[6]}px;'><textarea name='tcode[{$entry}]' style='width:200px; height:100px;'>{$tempcode}</textarea></div>".
				"<div class='rowdiv_0' style='width:{$dwidth[7]}px;'>{$config['author']}</div></td></tr>");
				
			}
		}
			
echo <<<EOT
		</table>
EOT;
if(!empty($tmporder)){
echo <<<EOT
		<table class="table_1" width="100%">
			<tr><td class="td_3"><input class="button_css" type="button" value="  提  交  " onclick="ajax_plugins()" /></td></tr>
		</table>

EOT;
}
echo <<<EOT
		</form>
	</div>
	<div id="t2"></div>
	<div id="t3"></div>
	<div class="div_clear" style="height:30px;"></div>
<script>
var hasErr=false;
var smallNowTab;
var pt = new Tabs();
pt.classpre="smalltab_";
pt.container = "smalltab_container";
pt.createTab("t1","论坛插件","",true,"n");
pt.init = function(){
	smallNowTab = pt.nowTab;
};
pt.onclick = function(){
	smallNowTab = pt.nowTab;
};		
pt.initTab();
pt.clickNowTab();

setRadioValue("tdefault","{$defaultstyle}");

function ajax_plugins(){
	popwin.loading();
	ajaxPost("pluginsform","plugins_ajax.php?action=install",ajax_plugins_callback);
}
function ajax_plugins_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"编辑成功","插件设置成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}

</script>

EOT;
	break;
	/************************************** list END ************************************************/
}	
?>